import GrimmRadio from '../Radio';
import { selectionBoxMixin } from '../../common/mixins/selectionBox';
const name = 'grimm-radio-group';
const childName = 'grimm-radio';
export default {
  name,
  mixins: [selectionBoxMixin],
  props: {
    value: [String, Number, Boolean],
    /**
     * 可选值：true|false
     * false：表示同一个radio点击第二次的时候，取消选中
     * true：和原生的radio行为一致
     */
    original: {
      type: [Boolean, String],
      default: false,
    },
    className: {
      default: name,
    },
    name: { default: '' },
    falseIcon: String,
    trueIcon: String,
  },
  components: { GrimmRadio },
  methods: {
    _onInnerClick(evt) {
      this.$emit('input', evt);
    },
  },
  render(h) {
    const children = this.options.map((option, idx) => {
      const props = Object.assign(Object.create(null), this.$props, {
        className: childName,
        label: option.label,
        name: option.value,
      });
      return h(childName, {
        on: {
          click: this._onInnerClick,
          input: val => this.$emit('input', val),
        },
        props,
        key: idx,
      });
    });
    return h('div', { class: name }, children);
  },
};
